r=(n+1)*rand(1);            %choose a number between '0' and 'n+1'
r=floor(r);                 %r becomes integer: 0, 1, 2, ..., n
vector=r;                   %vector receives the first position
last=vector(end);
iteration=iteration+1;